<?php
$this->breadcrumbs=array(
	'Security',
);?>
<script type="text/javascript">
<!--
	$(function(){
		$("#checkButton").button();
		$(".button").button().click(function(){
			$(this).parent().slideUp().next().fadeIn();
		});

/*		var str = '';
		$("input[name=sel_table]").click(function(){
			if($(this).attr("checked") ==true){
				str += ','+$(this).val();
			}
			$("#sel_tables").val(str);
			alert(str.substring(1,str.length));
		});
*/
		load();
	});

	function load(){
		$("#dblist").load("<?php echo $this->createUrl('dblist',array('r'=>time()));?>");
	}

	function chooseType(){
		if($("#backupWay").val() == "All"){
			$("#dataAll").show();
		}else{
			$("#dataTable").show();
		}
	}

	function submitWay(){
		$(".hide").hide();
		$("#stepLoading").show();
	}


	function back(object){
		
		object.parent().slideDown().prev().fadeIn();
		$("#step2>div").hide();
	}

	function backupAll(){
		 $.msgbox({
             height:100,
             width:250,
             content:{type:'confirm', content: '确实要备份该数据库所有内容？'},
             animation:4,
             onClose:function(v){
				if(v){
					submitWay();
					var filename = $("#backupName").val();
					$.post("<?php echo $this->createUrl('dbback');?>",{'filename':filename},function(msg){
					
						if(msg == "OK"){
							 $.msgbox({
					             height:100,
					             width:250,
					             content:{type:'alert', content: '备份该数据库成功！'},
					             animation:4,
					             onClose:function(v){
									load();
					             }
							 });
						}
					});
					return false;
				}else{
					$("#dataAll").show();
				}
             }
		 });
		

	}

	function backupTables(){

		 $.msgbox({
             height:100,
             width:250,
             content:{type:'confirm', content: '确实要备份该数据库所有内容？'},
             animation:4,
             onClose:function(v){
				if(v){
					submitWay();
					var tables = getSelectedInfo('sel_table');
					$.post("<?php echo $this->createUrl('savetables');?>",{'table':tables},function(data){
						if(data == "ok"){
							 $.msgbox({
					             height:100,
					             width:250,
					             content:{type:'alert', content: '备份该数据库成功！'},
					             animation:4,
					             onClose:function(v){
									load();
					             }
							 });							
						}
						
					});					
				}else{
					$("#dataTable").show();
				}
             }
		 });
		
		if(confirm){

			
		}else{
			
		}
	}


	function checkAll(object,item){
		$("input[name=" + item + "]").each(function(){
			if($(object).attr("checked") == true){
				$(this).attr("checked",true);
			}else{
				$(this).attr("checked",false);
			}
		});
	
		
	}

	function getSelectedInfo(item){
	    var str = '';	    
	    $("input[name='" + item + "']").each(function(i){
	        if($(this).attr('checked') == true){
	            str += ','+$(this).val();
	        }
	        
	    });
	    
	    str = str.substring(1);
		
		return str;

	    //arr = str.split(',');
	    //return arr;
	}

	function actionBatch(){
		var action = $("#checkDo").val();

		var ids = getSelectedInfo('bak_db');

		
		if(action == "delete"){

			 $.msgbox({
	               height:100,
	               width:250,
	               content:{type:'confirm', content: '确认要删除选中的链接吗？'},
	               animation:4,
	               onClose:function(v){
		       			$.post('<?php echo $this->createUrl('batch');?>',{'ids':ids},function(data){
		    				if(data == "ok"){
		    					 $.msgbox({
		    			               height:100,
		    			               width:250,
		    			               content:{type:'alert', content: '确认要删除选中的链接吗？'},
		    			               animation:4,
		    			               onClose:function(v){
		    								load();
		    			               }
		    					 });
		    				}
	
		    				
		    			});
	               }
			 });
			

		}else if(action == "restore"){
			alert(action);
		}
		
	}
		

//-->
</script>
<div class="column1 colborder">
	<div class="box">
		<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>Yii::t('admin','Back Up')));?>
			<div class="box-content">
				<div id="stepLoading" class="hide">loading……</div>
				<div id="step0">
					<br />
					数据备份提示：本数据备份系统有以下两类备份方式
					<ol>
						<li>把所有数据备份到一个单独文件，还原时则会覆盖整个数据库的所有数据</li>
						<li>单独备份每一个数据表的数据，还原时只影响相应数据表内容</li>
					</ol>
					
					单击下一步，选择备份方式<br /><br />
					<button type="button" class="button">下一步</button>
				</div>
				<div id="step1" class="hide">
		
					<br />
					<p>
						请选择数据备份方式：
						<select name="backupWay" id="backupWay">
							<option value="All">备份所有数据为单个文件</option>
							<option value="table">单表备份</option>
						</select>
					</p>		
					<button type="button" class="button" onclick="back($(this));">上一步</button>
					<button type="button" class="button" onclick="chooseType();">下一步</button>	
				</div>
				
				<div id="step2" class="hide">
					<div id="dataTable" class="hide">
						请选择要备份的数据表：						
						<hr />
						<input type="checkbox" name="sel_table_check" onclick="checkAll($(this),'sel_table');" />  全选
						<br />
						<?php foreach ($tables as $table):?>
						<div class="column3">
							<input type="checkbox" name="sel_table"  value="<?php echo $table;?>" />&nbsp;&nbsp;
							<?php echo $table;?>
						</div>
						<?php endforeach;?>	
						<div class="clear">
							<br />
							<button type="button" class="button" onclick="back($(this).parent().parent());">上一步</button>
							<button type="button" class="button" onclick="backupTables();">开始备份</button>	
						</div>
						
					</div>
					<div id="dataAll" class="hide">
						设置备份数据文件名称：<br />
						（注：如不填写，则会自动以数据库名称和当前时间为名命名）
						<br /><br />
						<input type="text" name="backupName" id="backupName" />
						<div class="clear">
							<br />
							<button type="button" class="button" onclick="back($(this).parent().parent());">上一步</button>
							<button type="button" class="button" onclick="backupAll();">开始备份</button>
						</div>	
					</div>	
				</div>				
			</div>
		<?php $this->endWidget();?>
	</div>	

</div>

<div class="column2">
	<div class="box">
		<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>Yii::t('admin', 'Data Reset'),	));?>
			<div class="box-content" id="dblist">
			
			</div>		
		<?php $this->endWidget();?>	
	</div>

</div>
